package xpn.platform.modules.sys.role;

import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.data.rest.core.config.Projection;
import xpn.platform.common.repository.XpnRepository;

@RepositoryRestResource(path = "roles", excerptProjection = DefaultProjection.class)
public interface SysRoleDAO extends XpnRepository<SysRole, Long> {

	/**
	 * 根据角色名查找角色
	 *
	 */
	SysRole findOneByName(String name);
	
	/**
	 * 根据老數據id查找角色：郑波2018-3-2增加
	 *
	 */
	@RestResource(path = "byOldId", rel = "byOldId")
	SysRole findOneByOldId(@Param(value = "param") String oldId);
}

/**
 * 缺省投影
 *
 * @author bobatkm
 *
 */
@Projection(name = "default", types = { SysRole.class })
interface DefaultProjection {
	String getName();

	Float getSortNo();

	String getDescription();
}

/**
 * 列表投影，用于返回关联属性
 *
 * @author bobatkm
 */
@Projection(name = "list", types = { SysRole.class })
interface ListProjection {
	String getName();

	Float getSortNo();

	String getDescription();

	@Value("#{target.fetchUserList()}")
	Set<String> getUserList();
}